//
//  DYServer.m
//  TestGizWits
//
//  Created by JM on 15/11/7.
//  Copyright © 2015年 JM. All rights reserved.
//

#import "DYServer.h"
#import <XPGWifiSDK/XPGWifiSDK.h>
#import "MDYRequest.h"
@interface DYServer()

@end

@implementation DYServer
singleton_implementation(DYServer)

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.requestArray = [NSMutableArray array];
    }
    return self;
}

- (void)addRequest:(id)aRequset {
    [self.requestArray addObject:aRequset];
    if (!self.isRequesting){
        self.isRequesting = YES;
        MDYRequest *request = self.requestArray[0];
        [XPGWifiSDK sharedInstance].delegate = request;
        [request didRealRequest];
        NSLog(@"%@",request);
    }
    NSAssert(self.requestArray.count <=1, @"暂不支持并行请求！！！！！！，请查看请求是否调用了superHandelResponse 或是不正确的请求顺序%@",self.requestArray);
    
    
}

- (void)removeRequest:(id)aRequset {
    
    [self.requestArray removeObject:aRequset];
    self.isRequesting = NO;
    if (self.requestArray.count) {
//        dispatch_async(dispatch_main(), ^{
//            
//        });

//        dispatch_async(dispatch_main(), ^{
//            
//        });
//       
//        MDYRequest *request = self.requestArray[0];
//        [request requstWithCompletionHandler:^(DYResponse *rs, NSError *error) {
//            request.block(rs,error);
//        }];
    }
}

#pragma mark-没时间了 先放这里
//- (void)didRealRequest {
////    [[XPGWifiSDK sharedInstance] setDeviceWifi:self.DY_ssid key:self.DY_key mode:XPGWifiSDKAirLinkMode softAPSSIDPrefix:@"XPG-GAgent" timeout:30 wifiGAgentType:nil];//@(XPGWifiGAgentTypeHF)//这个参数 设置错误 不会有任何提示
//}
//
////配置事件
//- (void)XPGWifiSDK:(XPGWifiSDK *)wifiSDK didSetDeviceWifi:(XPGWifiDevice *)device result:(int)result {
//    NSLog(@"没有配置receiveDelegate");
//    
//}
@end
